﻿using BigfootDNN.Mvc;
using YourCompany.Modules.MvcTemplate.ViewModel;

namespace YourCompany.Modules.MvcTemplate
{
    public class TimesheetController : BaseController
    {

        public ActionResult Timesheet()
        {
            return ViewResult("Timesheet", TimesheetViewModel.Create(Route));
        }

        public ActionResult AddEntry()
        {
            var ItemDate = GetValueOrErrorAsDate("ItemDate");
            var Desc = GetValueOrError("Description");
            var Hours = GetValueOrErrorAsDouble("Hours");

            return ViewResult("Timesheet_Grid", TimesheetViewModel.AddEntry(Route, ItemDate, Desc, Hours));
        }

        public ActionResult UpdateEntry()
        {
            var ItemId = GetValueOrErrorAsInt("ItemId");
            var ItemDate = GetValueOrErrorAsDate("ItemDate");
            var Desc = GetValueOrError("Description");
            var Hours = GetValueOrErrorAsDouble("Hours");
            return ViewResult("Timesheet_Grid", TimesheetViewModel.Update(ItemId, ItemDate, Desc, Hours, Route));
        }

        public ActionResult EditEntry()
        {
            var ItemId = GetValueOrErrorAsInt("ItemId");
            return ViewResult("EditTimeEntry", EditTimeEntryViewModel.Create(ItemId, Route));
        }

        public ActionResult Delete()
        {
            var ItemId = GetValueOrErrorAsInt("ItemId");
            return ViewResult("Timesheet_Grid", TimesheetViewModel.Delete(ItemId, Route));
        }

    }

}